/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.etop.weibo.servlet;

import com.etop.weibo.service.UserService;
import com.etop.weibo.util.WeiBoException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author jansing
 */
public class UserServlet extends BaseServlet {
    UserService userService = new UserService();
    /**
     * 登陆
     * param: name, password
     * return: user
     * @param req
     * @param resp
     * @return 
     */
    public String login(HttpServletRequest req, HttpServletResponse resp) {
            userService.login(req, resp);
            return "redirect:User?method=indexPage";
            //账号不存在 or 密码错误
    }

    public String logout(HttpServletRequest req, HttpServletResponse resp) {
        userService.logout(req, resp);
            return "redirect:User?method=loginPage";
    }

    /**
     * 注册 param: username, password, nickname, sex, introduction
     * @param req
     * @param resp
     * @return
     */
    public String personalSign(HttpServletRequest req, HttpServletResponse resp) throws WeiBoException {
            userService.sign(req, resp);
            return "redirect:User?method=loginPage";
            //账号已存在
    }
    
    public String officalSign(HttpServletRequest req, HttpServletResponse resp){
        
        return null;
    }
        

    /**
     * 发送私信 param: withWhoseId, what
     * @param req
     * @param resp
     * @return
     */
    public String sendSecret(HttpServletRequest req, HttpServletResponse resp) {
        userService.sendSecret(req, resp);
        return null;
    }

    /**
     * 关注
     * param: starId,
     * @param req
     * @param resp
     * @return
     */
    public String star(HttpServletRequest req, HttpServletResponse resp) {
        userService.star(req, resp);
        return null;
    }
    /**
     * 取关
     * param: starId,
     * @param req
     * @param resp
     * @return 
     */
    public String unStar(HttpServletRequest req, HttpServletResponse resp){
        userService.unStar(req, resp);
        return null;
    }
    
    /**
     * 发布微博
     * param: public-input,
     * @param req
     * @param resp
     * @return 
     */
    public String publish(HttpServletRequest req, HttpServletResponse resp){
        userService.publish(req, resp);
        return "redirect:User?method=indexPage";
    }
    
    /**
     * 删除微博
     * param: sayId,
     * @param req
     * @param resp
     * @return 
     */
    public String deleteWeibo(HttpServletRequest req, HttpServletResponse resp){
        userService.deleteWeibo(req, resp);
        return "redirect:User?method=indexPage";
    }
    
    /**
     * 赞
     * param: userId, sayId/commentId
     * @param req
     * @param resp
     * @return 
     */
    public String praise(HttpServletRequest req, HttpServletResponse resp){
        userService.praise(req, resp);
        return "redirect:User?method=indexPage";
    }
    
    /**
     * 取赞
     * param: userId, sayId/commentId
     * @param req
     * @param resp
     * @return
     */
    public String unPraise(HttpServletRequest req, HttpServletResponse resp){
        userService.unPraise(req, resp);
        return null;
    }
    
    /**
     * 评论
     * param: sayId, commentId 如果是评论评论的话需给出, what
     * @param req
     * @param resp
     * @return 
     */
    public String comment(HttpServletRequest req, HttpServletResponse resp){
        userService.comment(req, resp);
        return null;
    }
    
    /**
     * 删除评论
     * param: commentId,
     * @param req
     * @param resp
     * @return 
     */
    public String deleteComment(HttpServletRequest req, HttpServletResponse resp){
        userService.deleteComment(req, resp);
        return null;
    }
    
    public String loginPage(HttpServletRequest req, HttpServletResponse resp){
        return "/login.html";
    }
    
    public String signPage(HttpServletRequest req, HttpServletResponse resp){
        return "/registration.html";
    }
    
    
    /**
     * 跳转到主页
     * return: sayList,
     * todo: 关注数、粉丝数、微博数可能感兴趣的人
     * @param req
     * @param resp
     * @return 
     */
    public String indexPage(HttpServletRequest req, HttpServletResponse resp){
        userService.indexPage(req, resp);
        return "/WEB-INF/index.jsp";
    }
        
    /**
     * 个人主页
     * param: hostId,
     * return: host, sayList,
     * todo: 关注数、粉丝数、微博数
     * @param req
     * @param resp
     * @return 
     */
    public String personalCenter(HttpServletRequest req, HttpServletResponse resp){
        userService.personalCenter(req, resp);
        return "/WEB-INF/personalCenter.jsp";
    }
    
    
    /**
     * 进入某条微博
     * param: sqyId, 
     * return: say, u_cDTO,
     * todo: 关注数、粉丝数、微博数
     * @param req
     * @param resp
     * @return 
     */
    public String intoWeibo(HttpServletRequest req, HttpServletResponse resp){
        userService.intoWeibo(req, resp);
        //服务器端跳转
        return null;
    }
    
    /**
     * 显示待关注列表
     * return mayStarList
     * todo: host
     * @param req
     * @param resp
     * @return
     */
    public String showMayStarList(HttpServletRequest req, HttpServletResponse resp) {
        userService.showMayStarList(req, resp);
        return null;
    }
    
    /**
     * 显示关注列表
     * return starsList
     * todo: host
     * @param req
     * @param resp
     * @return 
     */
    public String showStarsList(HttpServletRequest req, HttpServletResponse resp){
        userService.showStarsList(req, resp);
        return null;
    }
    
    /**
     * 显示粉丝列表
     * return fansList
     * todo: host
     * @param req
     * @param resp
     * @return 
     */
    public String showFansList(HttpServletRequest req, HttpServletResponse resp){
        userService.showFansList(req, resp);
        return null;
    }
    
    /**
     * 显示私信面板 param: withWhoseId(null),
     * return: userList, withWhoseId, secretList
     * @param req
     * @param resp
     * @return
     */
    public String showSecret(HttpServletRequest req, HttpServletResponse resp) {
        userService.showSecret(req, resp);
        return null;
    }
}
